<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="author" content="zxh">
    <title>模拟select控件</title>
    <style>
        * {
            box-sizing: border-box;
        }
        
        ul,
        li {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        #box {
            width: 200px;
            height: 30px;
            margin: 100px auto;
            line-height: 30px;
            text-align: center;
            background-color: red;
            position: relative;
            cursor: pointer;
        }
        
        #box a {
            float: left;
            width: 100px;
            background-color: blue;
            text-decoration: none;
            background-color: lawngreen;
        }
        
        #box span {
            float: left;
            width: 100px;
            background-color: gray;
        }
        
        #box ul {
            width: 100px;
            border: 1px solid #ccc;
            position: absolute;
            top: 30px;
            left: 100px;
            display: none;
        }
        
        #box ul li {
            border-bottom: 1px dotted #ccc;
        }
        
        #box ul li:last-child {
            border: none;
        }
        
        #box ul li:hover {
            background-color: #ccc;
        }
    </style>
</head>

<body>
    <div id="box">
        <div>
            <a href="javascript:;">选择项目</a>
            <span class="select">未选择</span>
        </div>
        <ul class="list">
            <li>html5</li>
            <li>css3</li>
            <li>javascript</li>
            <li>jquery</li>
        </ul>
    </div>

</body>

</html>
<script src="js/jquery.js"></script>
<script>
    $('#box').click(function (ev) {
        // 阻止事件的传播
        ev.stopPropagation()
        $('#box ul').toggle()
        // 获取并显示内容
        $(this).find('ul li').each(function () {
            $(this).click(function () {
                $('#box span').html($(this).html());
            })

        })
    })
    // 点击空白处隐藏列表
    $(document).click(function () {
        $('box ul').hide()
    })

</script>